﻿#!/usr/bin/env python
# -*- coding: utf-8 -*-

'property usage example'

__author__='zhaoxp'

class Student(object):
	@property
	def score(self):
		return self._score
	
	@score.setter
	def score(self,value):
		if not isinstance(value,int):
			raise ValueError('socre must be an integer')
		if value<0 or value>100:
			raise ValueError('socre must be between 0 and 100')
		self._score=value
		
	@property
	def birth(self):
		return self._birth
	
	@birth.setter
	def birth(self,value):
		if not isinstance(value,int):
			raise ValueError('birth must be an integer')
		if value<1900 or value>2015:
			raise ValueError('birth must be between 1900 and 2015')
		self._birth=value
		
	@property
	def age(self):
		return 2015-self.birth
	
	pass
	

if __name__=='__main__':
	print "property usage example"
	s=Student()
	print "s=Student() =",s
	s.score=70
	print "s.score =",s.score
	s.birth=1982
	print "s.birth =",s.birth
	print "s.age =",s.age
	
	print "---------- last test ----------"
	print "it will throw error to run following "
	s.birth=3321
	s.age=32
	